// pages/experience/experience.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentTab:0,
    goodstypeList:[],
    goodsList:[]
  },

  changeTab:function(e){
    // console.log(e);
    var id = e.currentTarget.dataset.id;
    this.setData({
      currentTab:id
    });
  },
  changeBody:function(e){
    this.setData({
      currentTab: e.detail.current
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that=this;
    wx.request({
      url: app.globalData.apiUrl + "/goods/goodstype",
      data: {},
      success: function (res) {
        var goodstypeList = res.data;
        var goodsArr = [];
        for (var i = 0; i < goodstypeList.length; i++) {
          var obj = { typeid: goodstypeList[i].Id, typename: goodstypeList[i].typename, list: [] };
          goodsArr.push(obj);
        }
        that.setData({
          goodstypeList: goodstypeList
        });
        
        wx.request({
          url: app.globalData.apiUrl + "/goods",
          data: {},
          success: function (res1) {
            var goodsList = res1.data;
            for (var i = 0; i < goodsList.length; i++) {
              for (var j = 0; j < goodsArr.length; j++) {
                if (goodsArr[j].typeid == goodsList[i].typeid) {
                  goodsList[i].mainimg = app.globalData.resourceUrl + goodsList[i].mainimg;
                  goodsArr[j].list.push(goodsList[i]);
                }
              }
            }
            that.setData({
              goodsList: goodsArr
            });
            console.log(goodsArr);
          }
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})